package com.ktjy.ktmall.controller.vo;

import com.ktjy.common.annotation.Log;
import com.ktjy.common.core.controller.BaseController;
import com.ktjy.common.core.domain.AjaxResult;
import com.ktjy.common.core.page.TableDataInfo;
import com.ktjy.common.enums.BusinessType;
import com.ktjy.common.utils.poi.ExcelUtil;
import com.ktjy.ktmall.domain.vo.GoodsAttrValues;
import com.ktjy.ktmall.service.vo.IGoodsAttrValuesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品关联Controller
 *
 * @author ktjy
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/ktmall/goodsvalues")
public class GoodsAttrValuesController extends BaseController
{
    @Autowired
    private IGoodsAttrValuesService goodsAttrValuesService;

    /**
     * 查询商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:goodsvalues:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsAttrValues goodsAttrValues)
    {
        startPage();
        List<GoodsAttrValues> list = goodsAttrValuesService.selectGoodsAttrValuesList(goodsAttrValues);
        return getDataTable(list);
    }


    /**
     * 导出商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:goodsvalues:export')")
    @Log(title = "商品关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsAttrValues goodsAttrValues)
    {
        List<GoodsAttrValues> list = goodsAttrValuesService.list();
        ExcelUtil<GoodsAttrValues> util = new ExcelUtil<GoodsAttrValues>(GoodsAttrValues.class);
        util.exportExcel(response, list, "商品关联数据");
    }

    /**
     * 获取商品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('ktmall:goodsvalues:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsAttrValuesService.getById(id));
    }

    /**
     * 新增商品关联
     */
    @PreAuthorize("@ss.hasPermi('ktmall:goodsvalues:add')")
    @Log(title = "商品关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsAttrValues goodsAttrValues)
    {
        return toAjax(goodsAttrValuesService.insertGoodsAttrValues(goodsAttrValues));
    }

    /**
     * 修改商品关联
     */
    @PreAuthorize("@ss.hasPermi('ktmall:goodsvalues:edit')")
    @Log(title = "商品关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsAttrValues goodsAttrValues)
    {
        return toAjax(goodsAttrValuesService.updateById(goodsAttrValues));
    }

    /**
     * 删除商品关联
     */
    @PreAuthorize("@ss.hasPermi('ktmall:goodsvalues:remove')")
    @Log(title = "商品关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Integer> ids)
    {
        return toAjax(goodsAttrValuesService.removeByIds(ids));
    }
}